|
|
|
|
|
|
|
When the user drops the data onto the target, the target's OLEDragDrop event is triggered and the target checks the data from the source object to see whether it is the proper data type. Depending on the outcome, it either retrieves or rejects the data. To see this, add a second text box to the form in the project and set the OLEDROPMODE to Manual. Then place the following code in the form: |
|
|
|
|
|
|
|
|
Private Sub Text2_OLEDragDrop (Data As ComctlLib.DataObject, Effect As Long,_
Button As Integer, Shift As Integer, x As Single, y As Single)
If Data.GetFormat(vbcfText) then
MsgBox This data is text
End If
End Sub |
|
|
|
|
|
|
|
|
Caution Make sure that you use the OLEDragDrop event instead of the DragDrop event, which is used for non-OLE type processing. |
|
|
|
|
|
|
|
|
|
Now, run the application and try dragging data from the first text box to the second one. The only thing that should happen is that the message box should be displayed. To have the data in the text box, you would use the GetData method of the Data object that was passed to the control in the Drop event. If the data was stored automatically when the drag was started, the GetData method retrieves the data. If the data wasn't stored when the drag operation started, the source control's OLESetData event is triggered and the SetData method retrieves the data. |
|
|
|
|
|
|
|
|
When the data is accepted or rejected, the OLECompleteDrag event is triggered and the source can then perform the necessary clean-up. If the data is accepted and a move was requested, the source deletes the data. The most important concept to understand when using OLE drag and drop is knowing when the different events will occur and for which object. |
|
|
|
|
|
|
|
|
Whether you want to use the automatic or manual OLE drag-and-drop process really depends on the type of functionality you want the user to be able to perform when using your application. With automatic drag and drop, all operations are controlled by Windows and the internal Visual Basic process. You can drag text from one TextBox control to another by simply setting the OLEDragMode and OLEDropMode properties of these controls to Automatic. No code is required to respond to any of the OLE drag-and- |
|
|
|
|
|